import React, { Component } from "react";
import { SafeAreaView, Text, View, StyleSheet, TouchableOpacity, Image, TextInput, PermissionsAndroid, Platform, DeviceEventEmitter, Dimensions, ScrollView } from 'react-native';
import Constant from '../../utils/Constant'//全局变量
import { getImgUrl } from '../../utils/ComFunction';
import HttpUtils from "../../utils/HttpUtils";
import HttpUrls from "../../utils/HttpUrls";
import Header from "../../components/header";
import { ToastToUser } from "../../utils/CustomToast";
import ActionSheet from 'react-native-actionsheet'
import ImageCropPicker from 'react-native-image-crop-picker';
import Upload from '../../components/upload/Upload'
import { requestCameraPermission, requestWritePermission } from '../../utils/Permission';
import Loading from "../../utils/Loading";
import AndroidModule from "../../utils/AndroidConnent";
import PermissionDialog from "../../components/dialog/PermissionDialog";
const isIos = Platform.OS == 'ios';

const screenW = Dimensions.get('window').width;


export default class ContactUs extends Component {

    constructor(props) {
        super(props);
        this.state = {
            imgUrl: 'https://img.shuaiche.com/img/statics/app/service_wework.png',
            imgHeight: 400,
            dialogVisible: false
        };
    }

    componentDidMount() {
        Image.getSize(this.state.imgUrl, (width, height) => {
            this.setState({
                imgHeight: Math.floor(screenW / width * height)
            })
        }, error => {

        });
    }

    render() {
        const navigation = this.props.navigation;
        return (
            <View
                style={styles.container}>
                <Header navigation={navigation} Title={'平台客服'} />

                <ScrollView style={{ flex: 1, backgroundColor: '#fff', }} contentContainerStyle={{justifyContent: 'center', flexGrow: 1}} showsVerticalScrollIndicator={false}>
                    <Image style={{ width: '100%', height: this.state.imgHeight, }} source={{ uri: this.state.imgUrl }}></Image>
                </ScrollView>

                <View style={{ flexDirection: "row", width: '100%', paddingHorizontal: 15, height: Constant.bottomHeight + 60, paddingTop: 7, backgroundColor: '#fff' }}>
                    <TouchableOpacity
                        style={styles.btnConfirm}
                        onPress={() => {
                            this.downloadPic()
                        }}>
                        <Text style={{ color: '#333333', fontSize: 14 }}>下载二维码，微信扫码添加</Text>
                    </TouchableOpacity>
                </View>




                <PermissionDialog
                    visible={this.state.dialogVisible}
                    onClose={() => this.setDialogVisible(false)}
                    title={'申请文件读写存储权限'}
                    content={'获取文件读写存储权限，保存图片'}
                    permissions={[
                        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
                    ]}
                />

            </View>
        );
    }


    setDialogVisible(dialogVisible) {
        this.setState({
            dialogVisible: dialogVisible
        })
    }

    downloadPic() {
        if (isIos) {
            AndroidModule.downloadPictures({ imgList: [this.state.imgUrl] })
        } else {
            // PermissionsAndroid.check('android.permission.WRITE_EXTERNAL_STORAGE').then(res=>{
            //     console.log('PermissionsAndroid',res)
            //     if(!res){

            //         this.setDialogVisible(true)
            //     }
            //     else{

            //     }
            // }) 
            AndroidModule.downloadPictures({ imgList: [this.state.imgUrl] })
        }
    }



};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f9f9f9',
    },


    inputStyle: {

        width: '100%',
        backgroundColor: '#fff',
        padding: 10,
        fontSize: 14,
        color: '#333333'
    },

    btnConfirm: {
        height: 46,
        width: '100%',
        backgroundColor: '#ffde00',
        justifyContent: 'center',
        alignItems: 'center',
        borderRadius: 23
    }

});